Skip to content

fix(web): render Mermaid diagrams in Markdown - #6191

Open
adamblumoff wants to merge 5 commits into
pingdotgg:mainfrom
adamblumoff:fix/render-mermaid-markdown
Open

fix(web): render Mermaid diagrams in Markdown#6191
adamblumoff wants to merge 5 commits into
pingdotgg:mainfrom
adamblumoff:fix/render-mermaid-markdown

Conversation

@adamblumoff

@adamblumoff adamblumoff commented Aug 11, 2026

Copy link
Copy Markdown

Mermaid fences currently render as ordinary code blocks in T3 Code, so diagrams in Markdown lose the visual structure available in renderers that support Mermaid.

This change lazy-loads Mermaid when a completed Mermaid fence is present, serializes rendering because Mermaid configuration is global, and falls back to the original fenced code if rendering fails. Diagrams use strict security mode, follow the active theme, retain readable intrinsic sizing, and preserve their original Markdown for copy operations.

The shared web Markdown renderer covers chat, timelines, plans, Markdown file previews, and pull request bodies and reviews. Desktop inherits the web behavior; mobile remains unchanged because it uses a separate native renderer.

Validation

  • vp test run apps/web/src/components/MermaidDiagram.test.ts
  • vp lint apps/web/src/components/MermaidDiagram.tsx apps/web/src/components/MermaidDiagram.test.ts apps/web/src/components/ChatMarkdown.tsx apps/web/src/markdown-clipboard.ts
  • vp run --filter @t3tools/web typecheck
  • vp run --filter @t3tools/web build
  • Rendered a sequence diagram in dark and light themes in an isolated dev environment
  • Verified a 1247px diagram scrolls inside a 758px Markdown viewport

Model: GPT-5.6 Codex in T3 Code.

Note

Add Mermaid diagram rendering to ChatMarkdown

  • ChatMarkdown renders completed mermaid fenced blocks through the new MermaidDiagram component instead of source code. Streaming blocks and failed renders fall back to Shiki.
  • MermaidDiagram dynamically loads Mermaid, initializes with strict security and the active theme, and injects the SVG into a scrollable container.
  • Clipboard logic in markdown-clipboard.ts copies the original Mermaid source via data-markdown-copy when copying a rendered diagram.
  • Behavioral Change: Selections inside a data-markdown-copy ancestor copy explicit Markdown text instead of the rendered fragment. Streaming mermaid blocks render via Shiki.

Macroscope summarized cf50ae5.


Note

Medium Risk
Introduces client-side diagram rendering with injected SVG HTML in chat markdown; mitigated by Mermaid strict security, render fallbacks, and bounded copy serialization, but still expands untrusted-content parsing surface and bundle weight.

Overview
Chat markdown now renders completed mermaid fenced blocks as diagrams instead of Shiki code, while streaming messages still show the normal code path until the fence is finished.

A new MermaidDiagram path lazy-loads mermaid, runs renders on a global serial queue (because Mermaid config is shared), uses strict security settings and the active light/dark theme, and falls back to the existing highlighted code block on failure or while loading. Diagram containers get scroll-friendly layout CSS and the code-block wrap control is hidden when diagram output is shown.

Copy/paste is updated so rendered diagrams expose data-markdown-copy with a safely length-padded fence via serializeMarkdownCodeFence, and clipboard handling prefers that ancestor markdown when a selection only captures inner SVG text.

Reviewed by Cursor Bugbot for commit cf50ae5. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 284c4f42-9e37-43a2-a4f9-8c0c640879da

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:XL 500-999 changed lines (additions + deletions). labels Aug 11, 2026
Comment thread apps/web/src/components/MermaidDiagram.tsx Outdated
@macroscopeapp

macroscopeapp Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — This PR adds a production Mermaid dependency and changes the default rendering of completed Mermaid fences across the shared web Markdown renderer, including SVG injection and clipboard behavior. The new user-facing capability and security-sensitive rendering surface exceed a small isolated fix and warrant human review.

You can add or adjust custom eligibility rules. Learn more.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4653760dcf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/web/src/components/MermaidDiagram.tsx Outdated
Comment thread apps/web/src/components/MermaidDiagram.tsx Outdated
Comment thread apps/web/src/components/ChatMarkdown.tsx Outdated
Comment thread apps/web/src/index.css Outdated
@ekrako

ekrako commented Sep 3, 2026

Copy link
Copy Markdown

Would really like to see mermaid support land in some form. Agents lean on it heavily for architecture and flow diagrams, and today those blocks are just walls of source in the chat.

@t3dotgg @juliusmarminge this one and #8533 both tackle it. Could one of you pick a direction so the work isn't stuck?

@adamblumoff
adamblumoff force-pushed the fix/render-mermaid-markdown branch from fa0583d to 120a102 Compare September 3, 2026 23:52
Comment thread apps/web/src/components/ChatMarkdown.tsx Outdated
Comment thread apps/web/src/components/MermaidDiagram.tsx
Comment thread apps/web/src/components/MermaidDiagram.tsx
@adamblumoff
adamblumoff force-pushed the fix/render-mermaid-markdown branch from 120a102 to 38e6fa6 Compare September 4, 2026 00:04
Comment thread apps/web/src/components/MermaidDiagram.tsx

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 38e6fa6. Configure here.

Comment thread apps/web/src/components/MermaidDiagram.tsx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL 500-999 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants